<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   注册登录
 */
defined('IN_YuLin') || exit('NO PERMIT!');

if($a == 'logout')
{
    unset($_SESSION['user']);
    unset($_SESSION['uid']);

    ShowMsg('退出登录成功',MU('login/index'));
}

if($_uid)
{
	header('Location: '.MU('user'));
	exit;
}

if(IS_POST)
{
    $username	=	NoBadStr($_POST['username']);
    $password	=	NoBadStr($_POST['password']);
	
	!$username && AjaxReturn(2,'请输入账号');
	!$password && AjaxReturn(2,'请输入密码');

    $user = $db->getrow('SELECT * FROM '.Table('user').' WHERE username = \''.$username.'\'');
	!$user && AjaxReturn(2,'账号不存在');
	($user['status']) && AjaxReturn(3,'账号被锁定，请联系管理员');
	($user['password'] != Password($password)) && AjaxReturn(2,'密码错误');

    $_SESSION['uid'] = $user['id'];
	
    AjaxReturn(0,'登录成功');
}

$tpl->display('wap/login');